package com.rex.editor.common;


/**
 * @author Rex on 2019/6/20.
 */
public interface CommonJs {

    String REMIND = "remind";
    String GAMBIT = "gambit";
    String MATCHS = "matchs";


    /**
     * 为全局图片加上点击事件 回调 imageOnclick.openImage imageOnclick.openImage需要客户端对应实现
     * 时机为window.onload               style.height  200px 100%
     */
    String IMG_CLICK_JS = "<script type='text/javascript'>window.onload = function(){"
            + "var $img = document.getElementsByTagName('img');"
            + "for(var p in  $img){"
            + "    if (typeof $img[p] === 'object') {"
            + "        $img[p].style.width = '100%';"
            + "        $img[p].style.height ='350px';"
            + "        $img[p].style.objectFit ='cover';"
            + "        $img[p].onclick = function(e){"
            + "            ImgClick(e.srcElement.src);"
            + "        };"
            + "    }"
            + "}"
            //  gambit  话题设置点击事件
            + "var $gambit = document.getElementsByName('" + GAMBIT + "');"
            + "for(var p in  $gambit){"
            + "    $gambit[p].onclick = function(e){"
            + "      onTxtClick(e.srcElement.getAttribute('name') , e.srcElement.getAttribute('data'));"
            + "    };"
            + "}"
            //  remind  @联系人设置点击事件
            + "var $remind = document.getElementsByName('" + REMIND + "');"
            + "for(var p in  $remind){"
            + "    $remind[p].onclick = function(e){"
            + "      onTxtClick(e.srcElement.getAttribute('name') , e.srcElement.getAttribute('data'));"
            + "    };"
            + "}"
            //  matchs  @联系人设置点击事件
            + "var $matchs = document.getElementsByName('" + MATCHS + "');"
            + "for(var p in  $matchs){"
            + "    $matchs[p].onclick = function(e){"
            + "      onTxtClick(e.srcElement.getAttribute('name') , e.srcElement.getAttribute('data'));"
            + "    };"
            + "}"

            + "};"
            //图片点击事件
            + "function ImgClick(src) {"
            + "    var message = {"
            + "        'imgUrl' : src,"
            + "    };"
            + "   window.imageOnclick.openImage(src);"
            + "};"
            //文字点击事件
            + "function onTxtClick(type, arguments) {"
            + "   window.textOnclick.onTextClick(type,arguments);"
            + "};"
            + "</script>";


    String head = "<style>" +
            "img{" +
            " max-width:100%;" +
            " height:auto;" +
            "}\n"
            + "body{margin:0;padding:0}" +
            "</style>";

}
